import Koa from 'koa';
import Router from 'koa-router';
import postDataToJson from './middleware/postDataToJson/index.js';
import uploadToData from './middleware/uploadToData/index.js';
import routerRole from './routers/role/index.js';
import routerMenu from './routers/menu/index.js';
import routerUser from './routers/user/index.js';
import routerRoleManage from './routers/role-manage/index.js';
import routerField from './routers/field/index.js';
import routerModel from './routers/model/index.js';
import routerUpload from './routers/upload/index.js';
import routerContent from './routers/content/index.js';
import routerArticle from './routers/article/index.js';
import routerPreview from './routers/preview/index.js';
import routerWeixin from './routers/weixin/index.js';

export const run = () => {
  let router = new Router();
  const app = new Koa();

  app.use(uploadToData());
  app.use(postDataToJson());
  router.use('/api/role', routerRole.routes());
  router.use('/api/menu', routerMenu.routes());
  router.use('/api/user', routerUser.routes());
  router.use('/api', routerRoleManage.routes());
  router.use('/api/field', routerField.routes());
  router.use('/api/model', routerModel.routes());
  router.use('/api/upload', routerUpload.routes());
  router.use('/api/content', routerContent.routes());
  router.use('/api/article', routerArticle.routes());
  router.use('/preview', routerPreview.routes());
  router.use('/api/weixin', routerWeixin.routes());

  app.use(router.routes());
  app.use(router.allowedMethods());

  app.listen(3000);
};
